//
//  LiShiTaskViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/6/28.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "LiShiTaskViewController.h"
#import "LeeLiShiRenWuTableViewCell.h"
#import "LeeRenWuXXCYViewController.h"
@interface LiShiTaskViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView*tabView;
    int page;
}
@property(nonatomic,strong)NSMutableArray *bigArr;

@end

@implementation LiShiTaskViewController
-(void)viewWillAppear:(BOOL)animated{
    page=0;
    _bigArr = [NSMutableArray array];
    [self httpRenwuUrl];//参与任务
}
- (void)viewDidLoad {
    [super viewDidLoad];
    page=0;
    self.title=@"历史任务";
    [self setTab];
//    _bigArr = [NSMutableArray array];
//    [self httpRenwuUrl];
    //    self.view.backgroundColor=[UIColor redColor];
}
-(void)setTab
{
    tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, width_screen, height_screen-49-64-50) style:1];
     tabView.separatorColor = COLOR(229, 230, 231, 1);//分割线颜色
    tabView.delegate=self;
    //    tabView.mj_header
    tabView.dataSource=self;
    [tabView registerNib:[UINib nibWithNibName:@"LeeLiShiRenWuTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:tabView];
    
    //上拉加载
    __weak typeof(self) waekSelf = self;
    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        page++;
        [waekSelf httpRenwuUrl];
    }];
    [HTTPURL MJfoodDH:footer];
    tabView.mj_footer = footer;
    //下拉刷新
    MJRefreshGifHeader *hear = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        page=0;
        _bigArr = [NSMutableArray array];
        [waekSelf httpRenwuUrl];
    }];
    [HTTPURL MJheaderDH:hear];
    tabView.mj_header = hear;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _bigArr.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 40;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LeeLiShiRenWuTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (_bigArr.count>0) {
        cell.titleLabel.text = [NSString stringWithFormat:@"%@",_bigArr[indexPath.row][@"title"]];//b标题
//        cell.infoLab.text = [NSString stringWithFormat:@"%@",_bigArr[indexPath.row][@"description"]];//内容
        if (_bigArr[indexPath.row][@"rewardType"]) {
            switch ([_bigArr[indexPath.row][@"rewardType"]intValue]) {
                case 1001:
                     cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 元宝",_bigArr[indexPath.row][@"everyoneAmount"]];//元宝
                    break;
                case 1002:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 金币",_bigArr[indexPath.row][@"everyoneAmount"]];//金币
                    break;
                case 1003:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 金豆",_bigArr[indexPath.row][@"everyoneAmount"]];//金豆
                    break;
                case 1004:
                    cell.jindouLabel.text = [NSString stringWithFormat:@"%@ 额度",_bigArr[indexPath.row][@"everyoneAmount"]];//额度
                    break;
                    
                default:
                    break;
            }
        }
       
        

    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LeeRenWuXXCYViewController*vc=[LeeRenWuXXCYViewController new];
    vc.idString = _bigArr[indexPath.row][@"taskId"];
    vc.zhuangtaiInt = [_bigArr[indexPath.row][@"status"]intValue];
    vc.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:vc animated:YES];
}
//历史任务
-(void)httpRenwuUrl{
    NSLog(@"%@",CIT_number);
    NSString *nub = [NSString stringWithFormat:@"%@",CIT_number];
    NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/historyTasks.api?access_token="),NSUD_Obj(@"token")];
//    __weak typeof(self) waekself = self;
    [HTTPURL postRequest:url parameters:@{@"pageIndex":@(page),@"areaId":nub} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"retFlag"]integerValue]==1) {
            NSDictionary *dic = [PublicTools dictionaryWithJsonString:responseObject[@"data"]];
            NSArray *array = [NSArray array];
            array = dic[@"rows"];
            [_bigArr addObjectsFromArray:array];
            [tabView reloadData];
        }
        [tabView.mj_footer endRefreshing];
        [tabView.mj_header endRefreshing];
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
//cell 分割线 两端封头 实现这个两个方法 1
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
